package com.ctgu.demo03.controller;

import com.ctgu.demo03.service.StatisticsService;
import com.ctgu.demo03.utils.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName StasticsController
 * @Author Alex2
 * @Date 2025/3/11 22:26
 **/
@RestController
@RequestMapping("/api/statistics")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    /**
     * @Author: Alex
     * @Description: 插入修改数量
     */
    // http://localhost:8080/api/statistics/insertStatistic?name=modify&modify=0
    @GetMapping("insertStatistic")
    public ApiResult insertStatistic(@RequestParam("name") String name, @RequestParam("modify") Integer modify) {
        return statisticsService.insertStatistic(name, modify);
    }

    /**
     * @Author: Alex
     * @Description: 时间戳实现乐观锁
     */
    // http://localhost:8080/api/statistics/updateModify?id=1&modify=10
    @GetMapping("updateModify")
    public ApiResult updateModify(@RequestParam("id") Integer id, @RequestParam("modify") Integer modify) {
        return statisticsService.updateModify(id,modify);
    }
}